package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Name     string `gorm:"type:varchar(20);comment:用户名"`
	Password string `gorm:"type:varchar(20);comment:密码"`
}

func (User) TableName() string {
	return "user"
}

func (u *User) Register() error {
	return DB.Create(&u).Error
}

func (u *User) Login(name string, password string) (result User, err error) {
	err = DB.Where("name=? and password=?", name, password).Find(&result).Error
	if err != nil {
		return User{}, err
	}
	return result, nil
}
